IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[or_MemaUserSelect]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.[or_MemaUserSelect]
Go

CREATE  PROCEDURE  dbo.[or_MemaUserSelect]  
	@MeMaUserID			int = null

AS  
DECLARE 
   @TranCountAtEntry int, @DateTime datetime, @UserID int
  

BEGIN TRY

SELECT @TranCountAtEntry = @@TRANCOUNT
SELECT @DateTime  = getdate() 

IF @TranCountAtEntry  = 0 
BEGIN TRANSACTION 

SELECT
MeMaUserID				,
	UserTypeID		,				
	FirstName			,
	LastName			,
	Email					,
	Password				,
	IsActive			,
    LastModDate         ,
    CreatedDate       
    FROM MeMaUser

WHERE  MeMaUserID = ISNULL(@MeMaUserID,MeMaUserID)
 
IF @@TRANCOUNT > @TranCountAtEntry
COMMIT TRANSACTION

END TRY
BEGIN CATCH
  
  IF @@TRANCOUNT > @TranCountAtEntry
  ROLLBACK TRANSACTION

  -- Raise an error with the details of the exception
  or_raiseerror 

END CATCH
  